package com.texas_android.app.utils;

import android.util.Log;

import com.texas_android.app.Appconfig.AppConfig;

/**
 * Created by solin on 2017/4/24.
 */

public class Logger {
    private static final String LOG_TAG = "WWSR:";
    private static final int LOG_MAXLENGTH = 2000;
    private static boolean DEBUG = AppConfig.DEBUG;

    public Logger() {
    }

    public static void error(String log) {
        if (DEBUG)
            Log.e(LOG_TAG, log);
    }

    public static void log(String message) {
        if (DEBUG) {
            int strLength = message.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            if (message.length() > LOG_MAXLENGTH)
                for (int i = 0; i < 10; i++) {
                    if (strLength > end) {
                        Log.i(LOG_TAG, message.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.i(LOG_TAG, message.substring(start, strLength));
                        break;
                    }
                }
            else
                Log.i(LOG_TAG, "" + message);
        }
    }

    public static void log(String tag, String message) {
        if (DEBUG) {
            int strLength = message.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            if (message.length() > LOG_MAXLENGTH)
                for (int i = 0; i < 10; i++) {
                    if (strLength > end) {
                        Log.i(LOG_TAG, message.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.i(LOG_TAG, message.substring(start, strLength));
                        break;
                    }
                }
            else
                Log.i(LOG_TAG, "" + message);
        }
    }

    public static void line(String log) {
        if (DEBUG) {
            Log.i(LOG_TAG, "======================================Log Start=======================================");
            Log.i(LOG_TAG, "" + log);
            Log.i(LOG_TAG, "======================================Log End=========================================");
        }
    }

    public static void line() {
        if (DEBUG)
            Log.i(LOG_TAG, "=======================================================================================");
    }
}
